package csel.model;

public abstract class TimedEffect implements AreaEffect, Ticked, java.io.Serializable
{
	private static final long serialVersionUID = 1L;
	protected Entity e;
	GameGlobals globals;
	
	public TimedEffect()
	{
		globals = null;   // starts unattached
	}

	public boolean enter(Entity e)
	{
		if (globals == null)
			throw new GameNotAttachedException();
		
		this.doEffect(e);
		globals.getChronoTrigger().addTicked(this);
		System.out.println("ADDED!!!!!!");
		this.e = e;
		return true;
	}

	public boolean leave(Entity e)
	{
		if (globals == null)
			throw new GameNotAttachedException();
		
		if (globals.getChronoTrigger().removeTicked(this))
		{
			System.out.println("Success!!");
			System.out.println(this);
		}
		else
		{
			System.out.println("Failure: "+ this);
		}
		this.e = null;
		return true;
	}
	
	public void attach(GameGlobals globals)
	{
		this.globals = globals;
	}

	protected abstract void doEffect(Entity e);
}
